#include "downloadview.h"
#include "downloadmodel.h"
#include "downloaddelegate.h"
#include "taskrecord.h"

#include <QAbstractItemView>
#include <QDebug>
#include <QModelIndex>
#include <QSqlRecord>
#include <QHeaderView>

DownloadView::DownloadView(QWidget *parent) :
    QTableView(parent)
{
    setShowGrid(false);
    setEditTriggers(QAbstractItemView::NoEditTriggers);
    setSelectionBehavior(QAbstractItemView::SelectRows);
    setSelectionMode(QAbstractItemView::SingleSelection);
    setSortingEnabled(true);
    model = new DownloadModel(this);
    setItemDelegate(new DownloadDelegate(model, this));
    setModel(model);
    horizontalHeader()->setStretchLastSection(true);

    // Hiding useless things
    verticalHeader()->hide();

    // Hide total size
    hideColumn(3);
}

void DownloadView::insertNewTask(TaskRecord* taskRecord)
{
    model->enqueueNewTask(taskRecord);
}
